<%@ page contentType="text/html;charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <%@ include file="/common/dxp/include/common-base.jsp" %>
    <title>服务注册管理</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
</head>
<!-- Part 一、 以下是body主体内容的模块区域 -->
<body class="hold-transition ${sysColor} sidebar-mini">
<div class="wrapper">

    <!-- top start -->
    <%@include file="/common/dxp/top.jsp" %>
    <!-- top end -->
    <!-- left start -->
    <%@include file="/common/dxp/left.jsp" %>
    <!-- left end-->

    <div class="content-wrapper">
        <!-- Main start -->
        <section class="content">
            <div id="div_hidden_content" class="hidden" style="display:none;">
                <input name="templateType" type="hidden" value="all"/>
                <div id="hidden_common_final">
                    <!-- temp="hidden_common_final" start -->
                    <input name="mainObjName" type="hidden" value="dxInterfaceReg">
                    <input name="mainObjPrimaryKey" type="hidden" value="infoId">
                    <input name="objNameAll" type="hidden" value="dxInterfaceReg">
                    <!-- temp="hidden_common_final" end -->
                </div>
                <!-- temp="delForm_hidden" start -->
                <div id="delForm_hidden">
                    <input type="hidden" name="pageName" value="dx-interface-reg"/>
                    <input type="hidden" name="formName" value="delForm"/>
                </div>
                <!-- temp="delForm_hidden" end -->
            </div>

            <div class="box box-solid user-box">
                <div class="box-header with-border">
                    <h3 class="box-title">服务<span id="span_opt_title">新增</span> <span class="pl10 fx8 f12">（以下信息的填写请结合服务提供方所提供接口API规范进行填写！）</span></h3>
                    <button type="button" class="btn btn-default btn-sm pull-right" onclick="goBack()"><i class="fa fa-reply"></i> 返回 </button>
                </div>
                <div class="box-body">
                    <ul class="nav nav-tabs" id="tabHead-body">

                    </ul>
                    <div class="tab-content" id="tabContent-body">

                    </div>
                </div>
            </div>

            <div win-title="数据源选择" class="modal fade" id="my_modal_datasource" tabindex="-1" role="dialog"
                 aria-labelledby="myModalLabel" aria-hidden="true">
                <div class="modal-dialog" style="width:90%;">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                                ×
                            </button>
                            <h4 class="modal-title">
                                <font color="red">数据源选择</font> 
                            </h4>
                        </div>

                        <div class="modal-body">

                            <div class="box-body no-padding">
                                <div class="col-lg-7" style="height:500px;overflow-y: scroll;padding: 2px;">
                                    <table class="table table-bordered bordercolor">
                                        <thead>
                                        <tr>
                                            <th>序号</th>
                                            <th>数据源标识</th>
                                            <th>数据源类型</th>
                                            <th>连接地址</th>
                                            <th>操作</th>
                                        </tr>
                                        </thead>
                                        <tbody id="datasource-body">
                                        </tbody>
                                    </table>
                                </div>
                                <div class="col-lg-5" style="height:500px;overflow-y: scroll;padding: 2px;">
                                    <table class="table table-bordered bordercolor">
                                        <thead>
                                        <tr>
                                            <th class="w50">序号</th>
                                            <th>表名</th>
                                            <th>操作</th>
                                        </tr>
                                        </thead>
                                        <tbody id="selected_browTable_box_body">
                                        </tbody>
                                    </table>
                                </div>
                            </div>

                        </div>
                    </div>
                    <!-- /.modal-content -->
                </div>
            </div>

            <script type="text/template" id="tabHead-template">
                <? for ( var i = 0; i < rows.length; i++) {?>
                    <li><a href="#tab_<?=rows[i].id?>" data-toggle="tab"><?=rows[i].text?></a></li>
                <?}?>
            </script>
            <!-- Part 二、以下是template模板定义的模块区域 -->
            <script type="text/template" id="tabContent-template">
                <? for ( var i = 0; i < rows.length; i++) {?>
                    <? var code = rows[i].id?>
                    <? var formId = 'addForm_'+code?>
                    <div class="tab-pane" id="tab_<?=code?>">
                        <div class="box box-solid">
                            <div class="box-body">
                                <form class="form-horizontal addFormBody" data-model-code="<?=code?>" id="<?=formId?>" action="javascript:void(0)">
                                    <div class="">
                                        <input type="hidden" name="pageName" value="dx-interface-reg"/>
                                        <?if(!isEdit){?>
                                            <input type="hidden" name="formName" value="addForm"/>
                                            <input type="hidden" name="dxInterfaceReg.interfaceType" value="2"/>
                                            <input type="hidden" name="dxInterfaceReg.interfaceProtocol" value="<?=code?>"/>
                                        <?}else{?>
                                            <input type="hidden" name="formName" value="editForm"/>
                                            <input type="hidden" name="dxInterfaceReg.w_infoId" value="<?=infoId?>"/>
                                        <?}?>
                                    </div>
                                    <table class="table table-bordered">
                                        <tbody>
                                        <?if(!isEdit){?>
                                        <tr>
                                            <td class="w150" align="right"><label
                                                    class="form-control-static">所属单位：</label></td>
                                            <td class="w350">
                                                <div class="form-group">
                                                    <select id="<?=formId?>_dxSysReg_userOwner" name="dxInterfaceReg.userOwner" class="form-control  clean"
                                                            data-name="dxInterfaceReg.userOwner" data-dict-code="dictItemList" data-dict-cate="dxpUnit" data-type-tag="select" data-def=""
                                                            placeholder="必填项" data-bv-notempty="true" data-bv-notempty-message="不能为空" onchange="selectSys(this,'<?=formId?>')" >
                                                        <option value="">-请选择--</option>
                                                    </select>
                                                </div>
                                            </td>
                                            <td class="w150" align="right"><label
                                                    class="form-control-static">系统名称：</label></td>
                                            <td>
                                                <div class="form-group" id="<?=formId?>_dxSysReg_sysEname_div">
                                                    <select id="<?=formId?>_dxSysReg_sysEname"  class="form-control  clean"
                                                            name="dxInterfaceReg.sysEname" disabled
                                                            data-name="dxSysReg.sysEname" onchange="selectInterfaceType(this,'<?=formId?>')"
                                                            data-obj-name="dxSysReg"  data-type-tag="select"
                                                            data-colmun="{value:'sysEname',text:'sysCname',other:'sysType'}" data-page-name="dx-sys-reg" data-form-name="searchForm"
                                                            data-condition="dxSysReg.w_status=1" data-def="" data-dict-cate=""
                                                            placeholder="必填项" data-bv-notempty="true" data-bv-notempty-message="不能为空" >
                                                        <option value="">-请选择--</option>
                                                    </select>
                                                </div>
                                            </td>
                                        </tr>
                                        <?}?>
                                        <tr>
                                            <td class="w150" align="right"><label
                                                    class="form-control-static">服务编号：</label></td>
                                            <td class="w350">
                                                <div class="form-group"><input
                                                        name="dxInterfaceReg.interfaceCode"
                                                        class="form-control clean" maxlength="50"
                                                        data-name="dxInterfaceReg.interfaceCode"
                                                        placeholder="必填项，服务注册的编号" data-bv-notempty="true"
                                                        onblur="mytools.validFieldRepeat(this)" data-validate-repeat-selfname="dxInterfaceReg.w_infoId"
                                                        data-validate-repeat-message="服务编号已存在，请更换！"
                                                        data-bv-notempty-message="不能为空"></div>
                                            </td>
                                            <td class="w150" align="right"><label
                                                    class="form-control-static">服务名称：</label></td>
                                            <td>
                                                <div class="form-group"><input
                                                        name="dxInterfaceReg.interfaceName"
                                                        class="form-control clean" maxlength="80"
                                                        data-name="dxInterfaceReg.interfaceName"
                                                        placeholder="必填项，服务中文名称" data-bv-notempty="true"
                                                        onblur="mytools.validFieldRepeat(this)" data-validate-repeat-selfname="dxInterfaceReg.w_infoId"
                                                        data-validate-repeat-message="服务名称已存在，请更换其他名称！"
                                                        data-bv-notempty-message="不能为空"></div>
                                            </td>

                                        </tr>
                                        <tr class=" <?=('ftp'==code||'tcp'==code||'jms'==code||'jdbc'==code)?'hidden':''?> ">
                                            <td align="right"><label
                                                    class="form-control-static">请求方式：</label></td>
                                            <td>
                                                <div class="form-group">
                                                    <div class="form-control-static"
                                                         id="<?=formId?>_dxInterfaceReg_requestWay"
                                                         name="dxInterfaceReg.requestWay"
                                                         data-name="dxInterfaceReg.requestWay"
                                                         data-dict-code="dictItemList"
                                                         data-dict-cate="reqWay" data-colmun=""
                                                         data-condition="" data-type-tag="radio"
                                                         data-def="post">
                                                    </div>
                                                </div>
                                            </td>
                                         <?if('jdbc'!=code){?>
                                            <td align="right"><label
                                                    class="form-control-static">签名配置：</label></td>
                                            <td>
                                                <div class="form-group"><select
                                                        id="<?=formId?>_dxInterfaceReg_sign_conf_plug"
                                                        name="dxInterfaceReg.signConfPlug" data-name="dxInterfaceReg.signConfPlug"
                                                        class="form-control  clean"
                                                        data-obj-name="dxIntSignConf" data-dict-code="dymicSql" data-type-tag="select"
                                                        data-colmun="{value:'signCode',text:'signName'}" data-page-name="dx-int-sign-conf" data-form-name="searchForm"
                                                        data-def="" >
                                                    <option value="">--请选择--</option>
                                                </select></div>
                                            </td>
                                         <?}?>
                                        </tr>
                                        <tr class="<?=('jdbc'==code)?'hidden':''?>">
                                            <td align="right"><label
                                                    class="form-control-static">数据交换方向：</label></td>
                                            <td>
                                                <div class="form-group"><select  onchange="selectExchangeType(this,'#<?=formId?>_dxInterfaceReg_exchangeType')"
                                                        id="<?=formId?>_dxInterfaceReg_exchangeMode"  name="dxInterfaceReg.exchangeMode"
                                                        data-name="dxInterfaceReg.exchangeMode" class="form-control" data-type-tag="select"
                                                        data-bv-notempty="true" data-bv-notempty-message="不能为空">
                                                <?if('ftp'==code){?>
                                                    <option value="" remark="" selected="selected">--请选择--</option>
                                                    <option value="2" remark="">文件上传</option>
                                                    <option value="11" remark="">文件下载</option>
                                                <?}else if('jms'==code){?>
                                                    <option value="2" remark="" selected="selected">发送数据（适用于服务使用方直接向服务提供方发送数据的场景）</option>
                                                <?}else if('jdbc'==code){?>
                                                    <option value="12" remark="" selected="selected">主动获取数据（适用于服务使用方从服务提供方获取数据的场景）</option>
                                                <?}else if('tcp'==code||'webservice'==code){?>
                                                    <option value="" remark="" selected="selected">--请选择--</option>
                                                    <option value="2" remark="">发送数据（适用于服务使用方直接向服务提供方发送数据的场景）</option>
                                                    <option value="12" remark="">主动获取数据（适用于服务使用方从服务提供方获取数据的场景）</option>
                                                <?}else{?>
                                                    <option value="" remark="" selected="selected">--请选择--</option>
                                                    <option value="12" remark="">主动获取数据（适用于服务使用方从服务提供方获取数据的场景）</option>
                                                    <option value="2" remark="">发送数据（适用于服务使用方直接向服务提供方发送数据的场景）</option>
                                                    <option value="11" remark="">被动接收数据（适用于服务使用方上报数据给本系统）</option>
                                                <?}?>
                                                </select></div>
                                            </td>
                                            <td align="right"><label
                                                    class="form-control-static">数据交换类型：</label></td>
                                            <td>
                                                <div class="form-group"><select
                                                        id="<?=formId?>_dxInterfaceReg_exchangeType"
                                                        name="dxInterfaceReg.exchangeType"
                                                        class="form-control  clean"
                                                        data-name="dxInterfaceReg.exchangeType"
                                                        data-dict-code="dictItemList"
                                                        data-dict-cate="dataET" data-type-tag="select"
                                                        data-def="<?=(('jdbc'==code||'jms'==code)?'1':'')?>" placeholder="必填项"
                                                        data-bv-notempty="true"
                                                        data-bv-notempty-message="不能为空">
                                                    <option value="">--请选择--</option>
                                                </select></div>
                                            </td>
                                        </tr>

                                        <tr class="<?=('jdbc'==code)?'hidden':''?>">
                                            <td align="right"><label
                                                    class="form-control-static">请求<?=('ftp'==code)?'文件':'报文'?>格式：</label></td>
                                            <td>
                                                <div class="form-group"><select
                                                        id="<?=formId?>_dxInterfaceReg_reqMsgFormatType"
                                                        name="dxInterfaceReg.reqMsgFormatType"
                                                        class="form-control  clean"
                                                        data-name="dxInterfaceReg.reqMsgFormatType"
                                                        data-dict-code="dictItemList"
                                                        data-dict-cate="msgFormat" data-type-tag="select"
                                                        data-def="<?=('webservice'==code?'xml':'json')?>" placeholder="必填项"
                                                        data-bv-notempty="true"
                                                        data-bv-notempty-message="不能为空">
                                                    <option value="">--请选择--</option>
                                                </select></div>
                                            </td>
                                            <td align="right"><label
                                                    class="form-control-static">返回<?=('ftp'==code)?'文件':'报文'?>格式：</label></td>
                                            <td>
                                                <div class="form-group"><select
                                                        id="<?=formId?>_dxInterfaceReg_respMsgFormatType"
                                                        name="dxInterfaceReg.respMsgFormatType"
                                                        class="form-control  clean"
                                                        data-name="dxInterfaceReg.respMsgFormatType"
                                                        data-dict-code="dictItemList"
                                                        data-dict-cate="msgFormat" data-type-tag="select"
                                                        data-def="<?=('webservice'==code?'xml':'json')?>" placeholder="必填项"
                                                        data-bv-notempty="true"
                                                        data-bv-notempty-message="不能为空">
                                                    <option value="">--请选择--</option>
                                                </select></div>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td align="right"><label
                                                    class="form-control-static"><?=('jdbc'==code)?'JDBC连接':'服务'?>地址：</label></td>
                                            <td colspan="3">
                                                <div class="form-group">
                                                <?if('jdbc'==code){?>
                                                    <div class="input-group">
                                                        <input type="text" name="dxInterfaceReg.interfaceUri" data-name="dxInterfaceReg.interfaceUri" id="<?=formId?>_dxInterfaceReg_interfaceUri" class="form-control clean" placeholder="配置JDBC连接URL"  data-bv-notempty="true" data-bv-notempty-message="不能为空"/>
                                                        <div class="input-group-addon"><button class="btn btn-primary btn-xs" onclick="openDataSource(this,'#<?=formId?>_dxInterfaceReg_interfaceUri');" type="button">选择数据源</button></div>
                                                    </div>
                                                <?}else{?>
                                                    <input
                                                            name="dxInterfaceReg.interfaceUri"
                                                            class="form-control clean" maxlength="280"
                                                            data-name="dxInterfaceReg.interfaceUri"
                                                            placeholder="必填项，输入包含IP、域名等完整的URL地址" data-bv-notempty="true" data-bv-notempty-message="不能为空">
                                                <?}?>
                                                </div>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td align="right"><label
                                                    class="form-control-static">是否启用：</label></td>
                                            <td>
                                                <div class="form-group">
                                                    <div class="form-control-static"
                                                         id="<?=formId?>_dxInterfaceReg_enabled"
                                                         name="dxInterfaceReg.enabled"
                                                         data-temp-obj="dxInterfaceReg.enabled"
                                                         data-dict-code="dictItemList"
                                                         data-name="dxInterfaceReg.enabled"
                                                         data-dict-cate="enabled" data-colmun=""
                                                         data-condition="" data-type-tag="radio"
                                                         data-def="1">
                                                    </div>
                                                </div>
                                            </td>
                                            <td align="right"><label class="form-control-static"><?=('jdbc'==code)?'数据库':'服务'?>端口：</label></td>
                                            <td>
                                                <div class="form-group"><input name="dxInterfaceReg.interfacePort"
                                                                               data-name="dxInterfaceReg.interfacePort"  placeholder="必填项，<?=('jdbc'==code)?'数据库端口号':'若没有端口号请输入80'?>"
                                                                               class="form-control clean" maxlength="8" data-bv-notempty="true" data-bv-notempty-message="不能为空"></div>
                                            </td>
                                        </tr>
                                    <?if('ftp'==code||'jdbc'==code){?>
                                        <tr>
                                            <td align="right"><label
                                                    class="form-control-static"><?=('jdbc'==code)?'数据库':'FTP'?>用户名：</label></td>
                                            <td>
                                                <div class="form-group"><input
                                                        name="dxInterfaceReg.ftpUserName"  data-name="dxInterfaceReg.ftpUserName"
                                                        class="form-control clean" maxlength="30"
                                                        data-bv-notempty="true"
                                                        data-bv-notempty-message="不能为空"
                                                        placeholder="必填项，登录用户名User"
                                                        data-temp-obj="dxInterfaceReg.ftpUserName"></div>
                                            </td>
                                            <td align="right"><label
                                                    class="form-control-static"><?=('jdbc'==code)?'数据库':'FTP'?>密码：</label></td>
                                            <td>
                                                <div class="form-group"><input name="dxInterfaceReg.ftpPwd" data-name="dxInterfaceReg.ftpPwd"
                                                                               class="form-control clean"
                                                                               maxlength="30"
                                                                               data-bv-notempty="true"
                                                                               data-bv-notempty-message="不能为空"
                                                                               placeholder="必填项，登录密码Password"
                                                                               data-temp-obj="dxInterfaceReg.ftpPwd">
                                                </div>
                                            </td>
                                        </tr>
                                        <tr>
                                            <td align="right"><label
                                                    class="form-control-static"><?=('jdbc'==code)?'连接驱动':'FTP文件目录'?>：</label></td>
                                            <td>
                                                <div class="form-group">
                                                    <?if('jdbc'==code){?>
                                                        <select class="form-control clean" name="dxInterfaceReg.ftpPath" data-name="dxInterfaceReg.ftpPath" data-bv-notempty="true"  data-bv-notempty-message="不能为空" >
                                                            <option value="" selected="selected">--请选择--</option>
                                                            <option data-type="mysql" value="com.mysql.jdbc.Driver">com.mysql.jdbc.Driver</option>
                                                            <option data-type="oracle" value="oracle.jdbc.OracleDriver">oracle.jdbc.OracleDriver</option>
                                                        </select>
                                                    <?}else{?>
                                                        <input name="dxInterfaceReg.ftpPath" data-name="dxInterfaceReg.ftpPath"
                                                           class="form-control clean"  maxlength="30" data-bv-notempty="true"  data-bv-notempty-message="不能为空"
                                                           placeholder="必填项，文件存放目录" data-temp-obj="dxInterfaceReg.ftpPath">
                                                    <?}?>
                                                </div>
                                            </td>
                                            <?if('jdbc'==code){?>
                                            <td align="right"><label
                                                    class="form-control-static">签名配置：</label></td>
                                            <td>
                                                <div class="form-group"><select
                                                        id="<?=formId?>_dxInterfaceReg_sign_conf_plug2"
                                                        name="dxInterfaceReg.<?=(isEdit?'s_':'')?>signConfPlug" data-name="dxInterfaceReg.signConfPlug"
                                                        class="form-control  clean"
                                                        data-obj-name="dxIntSignConf" data-dict-code="dymicSql" data-type-tag="select"
                                                        data-colmun="{value:'signCode',text:'signName'}" data-page-name="dx-int-sign-conf" data-form-name="searchForm"
                                                        data-def="" >
                                                    <option value="">--请选择--</option>
                                                </select></div>
                                            </td>
                                            <?}?>
                                        </tr>
                                    <?}?>
                                        <tr>
                                        <tr>

                                            <td align="right"><label
                                                    class="form-control-static">描述：</label></td>
                                            <td colspan="3">
                                                <div class="form-group"><textarea
                                                        name="dxInterfaceReg.remark"
                                                        rows="2"
                                                        class="form-control clean" maxlength="180"
                                                        data-name="dxInterfaceReg.remark"
                                                        placeholder="必填项，服务内容详细描述" data-bv-notempty="true"
                                                        data-bv-notempty-message="不能为空"></textarea></div>
                                            </td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </form>
                            </div>
                            <div class="box-footer">
                                <div class="box-footer text-center">
                                    <button class="btn btn-success pull-left" type="button" onclick="initFormData('#<?=formId?>');"> 重置
                                    </button>
                                    <button class="btn btn-danger pull-right" type="button" onclick="submitForm1('<?=formId?>','');" > 提 交
                                    </button>
                                </div>
                            </div>
                        </div>
                    </div>
                <?}?>
            </script>

            <script type="text/template" id="datasource-template">
                <? for ( var i = 0; i < rows.length; i++) {?>
                <tr>
                    <td><?=(pageObj.currentPage-1)*10+(i+1)?></td>
                    <td><?=strUtil.doNull(rows[i].tRpcDatasource.sysEname,'')?></td>
                    <td><?=strUtil.doNull(rows[i].tRpcDatasource.databaseType,'')?></td>
                    <td><?=strUtil.subStr(rows[i].tRpcDatasource.jdbcUrl,40)?></td>
                    <td>
                        <div class="data-datasource-box hidden">
                            <input name="ftpPath" value="<?=strUtil.doNull(rows[i].tRpcDatasource.driverClassName,'')?>">
                            <input name="interfaceUri" value="<?=strUtil.doNull(rows[i].tRpcDatasource.jdbcUrl,'')?>">
                            <input name="ftpUserName" value="<?=strUtil.doNull(rows[i].tRpcDatasource.jdbcUsername,'')?>">
                            <input name="ftpPwd" value="<?=strUtil.doNull(rows[i].tRpcDatasource.jdbcPassword,'')?>">
                            <input name="dataName" value="<?=strUtil.doNull(rows[i].tRpcDatasource.dataName,'')?>">
                        </div>
                        <button type="button" class="btn btn-success btn-xs" onclick="checkedDataSource(this,1);"><i
                                class="fa fa-search-plus"></i> 查看数据表
                        </button>
                    </td>
                </tr>
                <?}?>
            </script>
            <script type="text/template" id="selected_browTable_box-template">
                <? for ( var i = 0; i < rows.length; i++) {?>
                    <tr>
                        <td><?=(i+1)?></td>
                        <td><?=rows[i]?></td>
                        <td>
                            <button type="button" class="btn btn-primary btn-xs" onclick="checkedDataSource(this,'<?=rows[i]?>');"><i class="fa fa-check-circle"></i> 选择使用</button>
                        </td>
                    </tr>
                <?}?>
            </script>

            <!-- Part 三、 以下是js模块区域 -->
            <script>
                var clickMenu = "int-reg-list";
                var myPage, dataListId, searchFormId;
                myPage = 10;//定义列表数据
                dataListId = "dataList";//显示列表数据div的id
                searchFormId = "searchForm";//搜索表单Id
                var paramFather = '<c:out value="${param.ps}"/>';
                var currTabId="#tab_http",currFormId='#addForm_http',currInfoId='',currProtocol='',isEdit=false;
                if(!strUtil.isNull(paramFather)){
                    var pramObj = JSON.parse($.base64.decode(paramFather));
                    currProtocol=pramObj.protocol;
                    currInfoId=pramObj.infoId;
                    currTabId="#tab_"+currProtocol;
                    currFormId="#addForm_"+currProtocol;
                    isEdit = true;
                }
                console.log(isEdit,currTabId,currFormId,currInfoId,currProtocol);
                var exchangeProtocolData={rows:[]};
                $.ajax({type:'get',async:false,dataType:'json',
                    url:ctx+"/js/dictData/dict-data-dataexchangeprotocol.js",
                    success:function(myData){
                        if(myData){
                            myData.forEach(function (item,i) {
                                if(!strUtil.isNull(item.id)){
                                    if(isEdit){
                                        if(currProtocol==item.id){
                                            //修改只加载当前
                                            exchangeProtocolData.rows.push({id:item.id,text:item.text,no:item.item.itemType});
                                        }
                                    }else{
                                        //新增加载所有
                                        exchangeProtocolData.rows.push({id:item.id,text:item.text,no:item.item.itemType});
                                    }
                                }
                            });
                            //按照某字段排序
                            exchangeProtocolData.rows.sort(function(a,b){
                                return a.no*1 - b.no*1
                            })
                        }
                    },
                    error:function(){
                        layer.alert("数据字典[数据交换协议]加载失败，请检查服务器！");
                    }
                });
                //初始化协议tab选项卡(排序
                exchangeProtocolData.isEdit = isEdit;
                exchangeProtocolData.infoId = currInfoId;
                console.log('exchangeProtocolData',exchangeProtocolData);
                $("#tabHead-body").html(baidu.template("tabHead-template", eval(exchangeProtocolData)));
                $("#tabContent-body").html(baidu.template("tabContent-template", eval(exchangeProtocolData)));
                var dictListMap = {};
                $(function ()  {

                    //控制选项卡
                    $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
                        var lastTabId =  $(e.relatedTarget).attr("href");   // 上一次活动的标签页
                        currTabId = $(e.target).attr("href");// 当前活动的标签页
                        $(currTabId).find("form").each(function (index) {
                            var formId ='#'+$(this).attr("id");
                            currProtocol = $(formId).attr("data-model-code");
                            currFormId=formId;
                            console.log('shown.tab',(index+1)+'->'+currTabId+"->"+currFormId,currProtocol);
                            initFormData(currFormId);
                        });
                    });

                    $(".nav-tabs a[href='"+currTabId+"']").tab('show');
                    //初始化表单：修改
                    if(isEdit){
                        $('#span_opt_title').text('修改');
                        initFormData(currFormId);
                        initInterFaceInfo();
                    }else{
                        initFormData(currFormId);
                    }

                    //2、控制是否启用token
                    //setToken();

                });
                function initFormData(formId){
                    console.log('initFormData',formId);
                    mytools.cleanData(formId);
                    setValidate(formId);//定义add表单验证属性
                    mytools.cleanValidate(formId);//清空上次校验规则提示
                    dictListMap = DictUtil.initDictAndDymic(currFormId);
                }

                //修改信息时，初始化对象
                function initInterFaceInfo() {
                    var paramData={'pageName':'dx-interface-reg','formName':'searchForm','dxInterfaceReg.w_infoId':currInfoId};
                    $.ajax({
                        type: "get",
                        url: common_info_url,
                        data: paramData, dataType: "json",
                        success: function (myData) {
                            console.log('dxInterfaceReg.info',myData);
                            if (myData) {
                                var ifrpObj = myData['dxInterfaceReg'];
                                console.log('currInfo',currProtocol,currTabId,currFormId);
                                FormUtil.loadView('dxInterfaceReg',ifrpObj,currTabId);
                            }
                        }
                    });
                }

                function goBack() {
                    var url =page_admin+'/int/int-reg-list';
                    mytools.pjax(url);
                }


                //注入日历框样式
                var dateObject = $('.datepicker').datepicker({
                    language: 'zh-CN',
                    //inline: true,
                    todayBtn: "linked",
                    format: "yyyy-mm-dd",
                    autoclose: true
                }).on('hide', function (e) {
                    //bootstrap datepicker与bootstrapValidator同时使用时选择日期后无法正常触发校验的解决方法
                    //当日期选择框关闭时，执行刷新校验。
                    var fieldName = $(this).attr("name");//获取当前元素name
                    var formId = $(this).parents("form").eq(0).attr("id");//获取当前元素所在父层级中的就近的formId
                    $("#" + formId).data('bootstrapValidator').updateStatus(fieldName, 'NOT_VALIDATED', null).validateField(fieldName);
                });

                //提交tab1表单数据
                function submitForm1(formId, tabId) {

                    //校验规则-表单提交时触发
                    var validate = $('#' + formId).data('bootstrapValidator').validate();
                    if (!validate.isValid()) { //如果校验不通过就返回
                        return;
                    }
                    var sysNameVal = $("#"+formId+"_dxSysReg_sysEname").val();

                    if(!isEdit && strUtil.isNull(sysNameVal)){
                        layer.alert("系统名称不能为空！");
                        return;
                    }
                    var modeCode = $("#"+formId).attr("data-model-code");
                    var index_submit = layer.confirm('您确定要保存信息吗？', {btn: ['Yes', 'No'], closeBtn: 0, offset: '220px'}
                        , function () {
                            var result = submitForm(formId, tabId);
                            if (result) {
                                layer.msg("提交成功！");
                                if('addForm_jdbc'==formId && !strUtil.isNull(this_datasourceData.tableName)){
                                    var interfaceCode= strUtil.doNull($('#'+formId).find("input[name='dxInterfaceReg.interfaceCode']").val(),"");
                                    var interfaceId = strUtil.doNull(result.result.dxInterfaceReg_infoId,"");
                                   saveProtoclDefaultMsg(modeCode,interfaceId,interfaceCode)
                                }else if('addForm_ftp'==formId){
                                    var interfaceCode= strUtil.doNull($('#'+formId).find("input[name='dxInterfaceReg.interfaceCode']").val(),"");
                                    var interfaceId = strUtil.doNull(result.result.dxInterfaceReg_infoId,"");
                                    saveProtoclDefaultMsg(modeCode,interfaceId,interfaceCode)
                                }else{
                                    goBack();
                                }
                            }
                        });

                }

                //提交表单数据
                function submitForm(formId, tabId) {
                    var result;
                    var index_load = layer.load(1, {shade: false});
                    $.ajax({
                        type: 'post',
                        url: common_submit_url,
                        data: $("#" + formId).serialize(),
                        async: false,
                        dataType: 'json',
                        success: function (myData) {
                            console.log(myData);
                            if (myData.flag == "T") {
                                result = myData;
                            } else {
                                setToken();
                                layer.alert(myData.msg);
                            }
                            layer.close(index_load);
                        },
                        error: function (e) {
                            layer.close(index_load);
                        }
                    });
                    return result;
                }
                //选择单位后，切换加载该单位下系统选项
                function selectSys(obj,formId) {
                    var option = $(obj).find("option:selected");
                    if(option.val()){
                        console.log(option.val());
                        // $("#"+formId+"_dxSysReg_sysEname").attr("data-condition","dxSysReg.w_sysType=2&dxSysReg.w_status=1&dxSysReg.w_userOwner="+option.val()).attr("data-dict-code","dymicSql");
                        $("#"+formId+"_dxSysReg_sysEname").attr("data-condition","dxSysReg.w_status=1&dxSysReg.w_userOwner="+option.val()).attr("data-dict-code","dymicSql");
                        $("#"+formId+"_dxSysReg_sysEname").attr("disabled",false);
                    }else {
                        $("#"+formId+"_dxSysReg_sysEname").attr("data-condition","").attr("data-dict-code","");
                        $("#"+formId+"_dxSysReg_sysEname").attr("disabled",true);
                    }
                    DictUtil.initDictAndDymic("#"+formId+"_dxSysReg_sysEname_div");
                }
                //切换-数据交换方向，控制数据交换类型默认值
                function selectExchangeType(obj,targetId) {
                    var formId = '#'+$(obj).parents("form").attr("id");
                    var modeCode = $(formId).attr("data-model-code");
                    var seledVal = $(obj).val();
                    console.log(formId,modeCode,seledVal,targetId);
                    switch (seledVal) {
                        case '2'://发送-都是同步
                            $(targetId).attr("readonly",true);
                            $(targetId).val('1');
                            break;
                        case '11'://被动接收-都是异步
                            $(targetId).attr("readonly",true);
                            $(targetId).val('2');
                            // $('#')
                            break;
                        case '12'://主动-分情况
                            $(targetId).attr("readonly",false);
                            break;
                    }
                }
                //根据系统类型（内外部），控制服务是外部服务2，还是内部接口1。
                function selectInterfaceType(obj,formId) {
                    var seledVal = $(obj).val();
                    var option = $(obj).find("option:selected");
                    var sysTypeVal = option.attr('sys-type');
                    // console.log(formId,seledVal,sysTypeVal);
                    $('#'+formId).find("input[name='dxInterfaceReg.interfaceType']").val(sysTypeVal);
                }

                //选择数据源
                function openDataSource(obj,objId) {
                    var index_load = layer.load(1, {shade: false});
                    $("#my_modal_datasource").modal("show");
                    var paramData={'pageName':'datasource-list','formName':'searchForm','tRpcDatasource.w_datasource1':'business'};
                    $.ajax({
                        type: "get",
                        url: common_list_url,
                        data: paramData, dataType: "json",
                        success: function (myData) {
                            layer.close(index_load);
                            console.log('datasource.list',myData);
                            if (myData.flag=='T') {
                                $("#datasource-body").html(baidu.template("datasource-template", eval(myData)));
                            }
                        }
                    });

                }
                //设置选中 赋值
                var this_datasourceData = {};
                function checkedDataSource(obj,typeNo) {
                    if(1==typeNo){
                        var index_load = layer.load(1, {shade: false});
                        var databoxObj = $(obj).parent().find(".data-datasource-box");
                        var thisTrObj = $(obj).parents("tr");
                        // if (!thisTrObj.hasClass('selected')) {
                            $('#datasource-body tr.selected').removeClass('selected');
                            thisTrObj.addClass('selected');
                        // }
                        databoxObj.find("input").each(function () {
                            this_datasourceData[$(this).attr('name')]=$(this).val();
                        });
                        $.ajax({
                            type: 'post',
                            url: '${ctx}/db/browTable/'+this_datasourceData.dataName+"/",
                            dataType: 'json',
                            success: function (myData) {
                                layer.close(index_load);
                                console.log('browTable',myData);
                                if(myData){
                                    var dataHtml = baidu.template("selected_browTable_box-template",eval(myData));
                                    $("#selected_browTable_box_body").html(dataHtml);
                                    $('#selected_browTable_box_body').on('click','tr', function (e) {
                                        if ( $(this).hasClass('selected') ) {
                                        }else {
                                            $('#selected_browTable_box_body tr.selected').removeClass('selected');
                                            $(this).addClass('selected');
                                        }
                                    } );
                                }
                            }
                        });
                    }else{
                        this_datasourceData['tableName']=typeNo;
                        console.log('this_datasourceData',this_datasourceData);
                        FormUtil.loadView('dxInterfaceReg',this_datasourceData,currFormId);
                        $("#my_modal_datasource").modal("hide");
                    }
                }

                //保存协议默认报文/参数
                function saveProtoclDefaultMsg(protocolCode,interfaceId,interfaceCode) {
                    var index_load = layer.load(1, {shade: false});
                    var defParamArry = [],defMsgType="params";
                    switch (protocolCode) {
                        case 'ftp':
                            defMsgType = "params";
                            defParamArry.push({paramEname:'fileName',paramCname:'文件名',defValue:''});
                            defParamArry.push({paramEname:'inputFileName',paramCname:'上传file对象名',defValue:'upfile'});
                            break;
                        case 'jdbc':
                            defMsgType = "header";
                            defParamArry.push({paramEname:'tableName',paramCname:'表名',defValue:this_datasourceData.tableName});
                            break;
                    }
                    $.ajax({
                        type: 'post',
                        url: common_submit_url,
                        data: {"dxMsgFormatSet.w_msgType": defMsgType,
                            "dxMsgFormatSet.w_interfaceId": interfaceId,"dxMsgFormatSet.w_interfaceCode": interfaceCode,
                            "pageName": "dx-msg-format-set", "formName": "delForm"
                        },
                        dataType: 'json',
                        success: function (myData) {
                           if(myData.flag='T'){
                               defParamArry.forEach(function (item,i) {
                                   var paramMap = {
                                       "dxMsgFormatSet.msgType": defMsgType, "dxMsgFormatSet.ifSubParam": "0","dxMsgFormatSet.ifNull": "1","dxMsgFormatSet.paramType": "2",
                                       "dxMsgFormatSet.paramEname": item.paramEname,"dxMsgFormatSet.paramCname": item.paramCname,"dxMsgFormatSet.cloumEname":item.paramEname,
                                       "dxMsgFormatSet.defValue": item.defValue,
                                       "dxMsgFormatSet.paramParent": "0","dxMsgFormatSet.interfaceRMFT": "json",
                                       "dxMsgFormatSet.interfaceId": interfaceId,  "dxMsgFormatSet.interfaceCode": interfaceCode,
                                       "pageName": "dx-msg-format-set","formName": "addForm","dxMsgFormatSet.ifUse": "0","dxMsgFormatSet.ifRowKey": "0"
                                   };
                                   $.ajax({
                                       type: 'post',
                                       url: common_submit_url,
                                       data: paramMap,
                                       dataType: 'json',
                                       success: function (myData) {
                                           console.log('saveProtoclDefaultMsg.'+interfaceCode+"."+protocolCode+"."+i,myData);
                                           if(i==(defParamArry.length-1)){
                                               layer.close(index_load);
                                               goBack();
                                           }
                                       }
                                   });
                               })
                           }
                        }
                    });
                }
                //设置token
                function setToken() {
                    $.ajax({
                        type: 'get',
                        url: '${ctx}/sendPage/token?token=true',
                        dataType: 'text',
                        success: function (myData) {
                            console.log(myData);
                            $('.formToken').val(myData);
                        }
                    });
                }


                /**** Part 四、以下是自定义新增方法  ****/
//1.定义校验规则-定义
                function setValidate(id) {
                    $(id).each(function () {
                        $(this).bootstrapValidator({
                            feedbackIcons: {
                                valid: 'glyphicon glyphicon-ok',
                                invalid: 'glyphicon glyphicon-remove',
                                validating: 'glyphicon glyphicon-refresh'
                            }, /** 以下需要结合实际业务清空补充个表单元素的验证规则 **/
                            fields: {
                                //* 可自定义新增验证规则
                                 "dxInterfaceReg.interfaceCode":{
                                     validators: {
                                         regexp: {
                                             regexp: /^[a-zA-Z0-9]+$/,
                                              message: '只能输入英文和数字组合'
                                          }
                                      }
                                },
                                "dxInterfaceReg.interfacePort":{
                                    validators: {
                                        regexp: {
                                            regexp: /^[0-9]+$/,
                                            message: '只能输入数字'
                                        }
                                    }
                                }
                            }
                        });
                    });
                }


            </script>
        </section>
        <!-- Main end -->
    </div>
    <!-- foot start -->
    <%@include file="/common/dxp/foot.jsp" %>
    <!-- foot start -->
</div>
<!-- /.content-wrapper -->
</body>
</html>











